﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_HealthAssignSrh
 * 类型：       
 * 功能说明：   
 * 作者：       谈
 * 创建日期：   2007/11/12
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Input.Dao;
using Shpm.App.Commons.Utils;
using Shpm.System;

public partial class App_Input_HealthAssignSrh : System.Web.UI.Page
{
    private const string COMMAND_SEARCH = "DoSearch";
    private const int JOB_ID = 34;//职位编号
    private const string GROUP_ID = "6";//部门编号

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {

            // 接收传递参数为检索条件
                ViewState["ParamCommand"] = Convert.ToString(Context.Items["ParamCommand"]);
                ViewState["TXT_ID"]=Convert.ToString(Context.Items["TXT_ID"]) ;
                ViewState["TXT_NAME"]=Convert.ToString(Context.Items["TXT_NAME"]);
            //
                txtName.Text = Convert.ToString(ViewState["TXT_NAME"]);
                txtId.Text = Convert.ToString(ViewState["TXT_ID"]);
            // 接收传递参数为分页编号
            if (Context.Items.Contains("ParamPageIndex"))
            {
                GridView1.PageIndex = Convert.ToInt32(Context.Items["ParamPageIndex"]);
            }
        }
    }
    #endregion

    #region 读取数据
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (COMMAND_SEARCH.Equals(ViewState["ParamCommand"]))
        {
            // 构建检索条件对象
            MstEmployeeBean dataBean = new MstEmployeeBean();
            dataBean.EmployeeId = Convert.ToString(ViewState["TXT_ID"]);
            dataBean.EmployeeName = Convert.ToString(ViewState["TXT_NAME"]);
            dataBean.JobId = JOB_ID;
            // 检索结果绑定到控件
            HealthAssignDao dao = new HealthAssignDao();
            IList dataList = dao.FindByEmployee(dataBean);
            GridView1.DataSource = dataList;
            GridView1.DataBind();

            tblResult.Visible = dataList.Count > 0;
        }
        else
        {
            tblResult.Visible = false;
        }
    }
    #endregion

    #region GridView1_PageIndexChanging
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView1.PageIndex = e.NewPageIndex;
    }
    #endregion

    #region 分配按钮
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        Context.Items["EMPLOYEE_ID"] = row.Cells[0].Text;
        Context.Items["EMPLOYEE_NAME"] = row.Cells[1].Text;
        Context.Items["TXT_ID"] =  Convert.ToString(ViewState["TXT_ID"]);
        Context.Items["TXT_NAME"] =  Convert.ToString(ViewState["TXT_NAME"]);
        Context.Items["ParamPageIndex"] = GridView1.PageIndex;
        Context.Items["ParamCommand"] = Convert.ToString(ViewState["ParamCommand"]);
        ControllerUtils.Transfer(this.Context, "~/App/Input/HealthAssignDetail.aspx", true);
    }
    #endregion

    #region 检索按钮
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        //SysUserManager manager = new SysUserManager(Context);
        //SysUserBean sysUserBean = manager.getSysUserBean();
        //MstSysUserBean mstSysUserBean =
        //    sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        //MstEmployeeBean mstEmpBean =
        //    sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        //string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        //string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;

        //MstEmployeeBean dataBean = new MstEmployeeBean();
        //dataBean.EmployeeId = emplyId;
        //HealthAssignDao dao = new HealthAssignDao();
        //IList dataList = dao.FindByEmployee(dataBean);
        //if (dataList.Count > 0)
        //{
        //    dataBean = (MstEmployeeBean)dataList[0];
        //}
        //if (dataList.Count == 0 || !dataBean.DepartId.Equals(GROUP_ID) || Convert.ToString(dataBean.JobLimit) == "0")
        //{
        //    ((Design_MasterPage)this.Master).InfoMessage =
        //        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
        //    return;
        //}
        ViewState["TXT_ID"] = txtId.Text.Trim();
        ViewState["TXT_NAME"] = txtName.Text.Trim();
        ViewState["ParamCommand"] = COMMAND_SEARCH;
    }
    #endregion
}
